/*
 * @Author: hongbin
 * @Date: 2022-12-22 10:25:33
 * @LastEditors: hongbin
 * @LastEditTime: 2022-12-22 14:20:18
 * @Description:删除动态
 */
import { ObjectId } from "mongodb";
import { NextApiRequest, NextApiResponse } from "next";
import DB from "../mongodb";

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
    const db = await DB;
    const { id } = req.query;
    if (!id) return res.status(501).json({ code: -1, msg: "未传递参数id" });
    const del = await db.collection("topic").deleteOne({ _id: new ObjectId(id as string) });
    console.log(del);

    if (del.deletedCount) {
        res.json({ data: "删除成功" });
    }
}
